using System;
using Core;
using FindItNow.Features;
using EnvDTE;
using EnvDTE80;
using Extensibility;

namespace FindItNow
{
	public class Connect : IDTExtensibility2, IDTCommandTarget
	{
		private Ide _ide;
		private AddIn _addIn;
		private CommandRegistrar _commandRegistrar;
	    private OutputPane _outputPane;
		private FindInSolutionFeature _findFeature;

		public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
		{
			_ide = new Ide((DTE2) application);
			_addIn = (AddIn)addInInst;
			_commandRegistrar = new CommandRegistrar("FindItNow.Connect.", _ide.Commands, _ide.FindCommandBar("Amnesia"), _addIn);
            _outputPane = new OutputPane(_ide.CreateOutputPane("FindItNow"));
			_findFeature = new FindInSolutionFeature(_ide, _outputPane);

			_commandRegistrar.Register(_findFeature);
		}

		public void OnDisconnection(ext_DisconnectMode disconnectMode, ref Array custom)
		{
		}

		public void OnAddInsUpdate(ref Array custom)
		{
		}

		public void OnStartupComplete(ref Array custom)
		{
		}

		public void OnBeginShutdown(ref Array custom)
		{
		}

		public void Exec(string commandName, vsCommandExecOption executeOption, ref object variantIn, ref object variantOut, ref bool handled)
		{
			handled = _commandRegistrar.Exec(commandName.Replace(_commandRegistrar.Prefix, ""));
		}

		public void QueryStatus(string commandName, vsCommandStatusTextWanted neededText, ref vsCommandStatus statusOption, ref object commandText)
		{
			if (neededText != vsCommandStatusTextWanted.vsCommandStatusTextWantedNone)
				return;

            statusOption = _commandRegistrar.QueryStatus(commandName.Replace(_commandRegistrar.Prefix, ""));
		}
	}
}